//
//  JZBPopDetailViewController.m
//  JZB
//
//  Created by liujianlong on 2022/8/31.
//

#import "JZBPopDetailViewController.h"
#import "JZBAddPayViewController.h"
#import "JZBAddImgCell.h"

@interface JZBPopDetailViewController ()
@property (strong, nonatomic) IBOutlet UIView *bgPopView;
@property (strong, nonatomic) IBOutlet UILabel *theme;
@property (strong, nonatomic) IBOutlet UIImageView *typeImg;
@property (strong, nonatomic) IBOutlet UILabel *type;
@property (strong, nonatomic) IBOutlet UILabel *money;
@property (strong, nonatomic) IBOutlet UILabel *bank;
@property (strong, nonatomic) IBOutlet UILabel *time;
@property (strong, nonatomic) IBOutlet UICollectionView *collectionView;
@property (strong, nonatomic) IBOutlet UILabel *moneyType;
@end

@implementation JZBPopDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    CGRect bounds = CGRectMake(0, 0, SCREEN_WIDTH, 540);
    UIBezierPath * path = [UIBezierPath bezierPathWithRoundedRect:bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(20, 20)];
    CAShapeLayer *layer = [CAShapeLayer layer];
    layer.frame = bounds;
    layer.path = path.CGPath;
    self.bgPopView.layer.mask = layer;
    [self.collectionView registerNib:[JZBAddImgCell nib] forCellWithReuseIdentifier:[JZBAddImgCell ID]];
}
- (void)setModel:(JZBBook *)model{
    _model = model;
    [self initUI];
    [self.collectionView reloadData];
}
- (void)initUI{
    self.theme.text = self.style == AddStylePay ? LS(@"支付详情") : LS(@"收入详情");
    self.typeImg.image = [UIImage imageNamed:self.model.type];
    self.type.text = LS(self.model.type);
    self.money.text = self.model.money;
    self.bank.text = LS(self.model.from);
    self.moneyType.text = self.style == AddStylePay ? LS(@"支付金额") : LS(@"收入金额");
    self.time.text = [NSDate transToDate:@"yyyy/MM/dd" :self.model.stamp];
}
- (IBAction)actionforBtn:(UIButton *)sender {
    [self dismissViewControllerAnimated:NO completion:^{
        if (self.block) {
            self.block((int)sender.tag);
        }
    }];
}

#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return  self.model.data.count;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    JZBAddImgCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:[JZBAddImgCell ID] forIndexPath:indexPath];
    cell.img.image = [UIImage imageWithData:self.model.data[indexPath.row]];
    cell.cancelbtn.hidden = YES;
    cell.imgLeft.constant = 0;
    cell.imgRight.constant = 0;
    cell.imgTop.constant = 0;
    return  cell;
}

#pragma mark - UICollectionViewDelegate
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
}
#pragma mark - UICollectionViewDelegateFlowLayout
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return  CGSizeMake(collectionView.frame.size.height,collectionView.frame.size.height);
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return  UIEdgeInsetsMake(0, 0, 0, 0);
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return 15;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    return 15;
}

@end
